/*
 * Copyright (C) 2020 The LINN Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.juqimiao.linn.exception;

import com.juqimiao.linn.config.FrameworkConfig;
import com.juqimiao.linn.context.ApplicationContextWrapperI;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.stereotype.Component;

/** Todo: 重构，使用 config模式在设计时确定使用默认Handler或者使用自定义Handler */

/**
 *
 * 异常处理工厂类。
 *
 * @author  Collin Cai
 */
@Component
public class ExceptionHandlerFactory {

    private static ApplicationContextWrapperI applicationContextWrapper = FrameworkConfig.getWrapper();

    /**
     * 获取异常处理对象。
     *
     * @return 一个异常处理对象。
     */
    public static ExceptionHandlerI getHandler() {
        try {
            return applicationContextWrapper.getBean(ExceptionHandlerI.class);

        } catch (NoSuchBeanDefinitionException ex) {
            return DefaultExceptionHandler.getInstance();
        }
    }
}
